base64 = {
    map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    decode: function(a) {
        var b = binary = '';
        for (var i = 0; i < a.length; i++) {
            if (a.substr(i, 1) == '=') {
                break
            };
            var c = this.map.indexOf(a.charAt(i)).toString(2);
            binary += {
                1: '00000',
                2: '0000',
                3: '000',
                4: '00',
                5: '0',
                6: ''
            }[c.length] + c
        };
        binary = binary.match(/[0-1]{8}/g);
        for (var i = 0; i < binary.length; i++) {
            b += String.fromCharCode(parseInt(binary[i], 2))
        };
        return b
    }
};
content = {
    index: 0,
    step: 5,
    star: 0,
    add: 0,
    state: 'load',
    showState: 'no',
    childNode: [],
    load: function() {
        var e = base64.decode(document.getElementsByTagName('meta')[4].getAttribute('content')).split(/[A-Z]+%/);
        var j = 0;

        function r(a) {
            return a;
            var c = '';
            var d = document.createElement('span');
            for (var i = 0; i < 20; i++) {
                var n = Math.floor(Math.random() * 99001 + 1000);
                c += String.fromCharCode(n)
            };
            var b = ['。', '：', '？', '！', '—', '…', '；', '，', '”', ''];
            c += b[Math.floor(Math.random() * b.length)];
            d.style.color = '#fff';
            d.style.fontSize = '0';
            d.style.lineHeight = '0';
            d.style.position = 'absolute';
            d.style.top = 0;
            d.style.left = 0;
            d.appendChild(document.createTextNode(c));
            a.appendChild(d);
            return a
        };
        for (var i = 0; i < e.length; i++) {
            if (e[i] < 5) {
                this.childNode[e[i]] = r(this.box.childNodes[i + this.star]);
                j++
            } else {
                this.childNode[e[i] - j] = r(this.box.childNodes[i + this.star])
            }
        };
        console.log(this.childNode);
        this.show()
    },
    check: function() {
        return this.showState == 'yes' && content.button.style.display != 'none' && this.offsetTop + this.button.offsetTop - Math.max(document.body.scrollTop, document.documentElement.scrollTop) < document.documentElement.clientHeight ? true : false
    },
    init: function(a, b) {
        if (!b) {
            return false
        };
        this.time = new Date().getTime();
        this.box = a;
        this.button = b;
        this.offsetTop = 0;
        this.randomContent = [];
        this.hiddenItem = [];
        this.showItem = [];

        function random() {
            return String.fromCharCode(Math.floor(Math.random() * 25 + 97)) + Math.floor(Math.random() * (1000000000))
        };
        var c = document.styleSheets[2];
        for (var i = 0; i < 100; i++) {
            this.showItem.push(random());
            this.hiddenItem.push(random())
        };
        if (c.insertRule) {
            c.insertRule('#content .' + this.hiddenItem.join(',#content .') + '{display:none;}', 0);
            c.insertRule('#content .' + this.showItem.join(',#content .') + '{display:block;}', 0)
        } else {
            for (var i = 0; i < this.hiddenItem.length; i++) {
                c.addRule('#content .' + this.hiddenItem[i], 'display:none');
                c.addRule('#content .' + this.showItem[i], 'display:block')
            }
        };
        for (var i = 0; i < this.box.childNodes.length; i++) {
            if (this.box.childNodes[i].tagName == 'H2') {
                this.star = i + 1
            };
            if (this.box.childNodes[i].tagName == 'DIV' && this.box.childNodes[i].className != 'chapter') {
                break
            }
        };
        console.log(this.star);
        /\/([0-9]+)\/([0-9]+)\./.test(location.href);
        this.sid = RegExp.$2;
        this.load();
        window.onscroll = function() {
            if (content.check()) {
                content.showNext()
            }
        }
    },
    show: function() {
        this.showState = 'no';
        var a = 0;
        for (var i = this.index; i < this.childNode.length; i++) {
            if (this.childNode[i].nodeType != 1) {
                continue
            };
            a += this.childNode[i].innerHTML.length;
            this.index = i + 1;
            this.childNode[i].className = content.showItem[Math.floor(Math.random() * 100)];
            this.box.appendChild(this.childNode[i]);
            for (var j = 0; j < 5; j++) {
                var b = this.childNode[Math.floor(Math.random() * this.childNode.length)].cloneNode(true);
                b.className = content.hiddenItem[Math.floor(Math.random() * 100)];
                this.box.appendChild(b)
            };
            if (a > 500) {
                break
            }
        };
        var c = getCookie(this.sid);
        if (!c || c < this.index || c > this.childNode.length + 1) {
            addCookie(this.sid, this.index, location.pathname)
        };
        content.time = getCookie(this.sid) > this.index ? 0 : new Date().getTime();
        if (this.index >= this.childNode.length) {
            this.button.style.display = 'none'
        } else {
            this.showState = 'yes';
            if (this.check()) {
                this.showNext()
            }
        }
    },
    showNext: function() {
        if (this.showState == 'no') {
            return false
        };
        this.showState = 'no';
        setTimeout(function() {
            content.show()
        }, Math.max(0 - (new Date().getTime() - content.time), 0))
    }
};